<?php
class Cms_Doctrine_Search
{
	private $SearchQuery;
	private $SearchParams;
	private $Table;
	
	public function __construct($table)
	{
		$this->Table = trim($table);
		
		$this->SearchQuery = Doctrine::getTable($this->Table)
               ->getTemplate('Doctrine_Template_Searchable')
               ->getPlugin();
	}
	
	public function search($params)
	{
		$params = trim($params);
		$this->SearchParams .= ' '. $params;
	}	
	
	public function execute()
	{
		$resultSet = $this->SearchQuery->search($this->SearchParams);
		$collection = new Doctrine_Collection(Doctrine::getTable($this->Table)); 
		
		$resultId = NULL;
		foreach($resultSet as $docId)
		{
			if(empty($resultId))
				$resultId .= $docId['id'];
			else
				$resultId .= ','.$docId['id'];
		}
		
			$query = new Doctrine_Query();
			$query->select('title,description')
			      ->from($this->Table)
				  ->where('id IN ('.$resultId.')');
			$result = $query->execute();
			
			//$record = Doctrine::getTable($this->Table)->find($docId['id']); 
			//$collection->add($result);
		
		return $result;
	}
}